from pydantic import BaseModel, Field
from datetime import datetime, date
from typing import Optional

class ClassStudentBase(BaseModel):
    class_id: int = Field(..., description="班级ID")
    student_id: int = Field(..., description="学生ID")
    join_date: date = Field(..., description="加入日期")
    leave_date: Optional[date] = Field(None, description="离开日期")
    status: int = Field(1, description="状态：0-已离开 1-在读")

class ClassStudentCreate(ClassStudentBase):
    """创建班级学生关联时使用的模型"""
    pass

class ClassStudentUpdate(BaseModel):
    """更新班级学生关联时使用的模型"""
    class_id: Optional[int] = None
    student_id: Optional[int] = None
    join_date: Optional[date] = None
    leave_date: Optional[date] = None
    status: Optional[int] = None

class ClassStudent(ClassStudentBase):
    id: int
    create_time: Optional[datetime] = Field(None, description="创建时间")
    update_time: Optional[datetime] = Field(None, description="更新时间")
    
    class Config:
        from_attributes = True